package cn.wolfcode.crm.shrio.realm;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;

public class CRMRealm extends AuthorizingRealm {

    /**
     * 提供授权相关信息
     *
     * @param principals
     * @return
     */
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
        return null;
    }

    /**
     * 提供认证相关信息
     *
     * @param token
     * @return
     */
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        //获取登录的用户名
        Object principal = token.getPrincipal();
        System.out.println(principal);
        String username = "mao";
        String password = "1";
        if (username.equals(principal)) {
            return new SimpleAuthenticationInfo(username, password, "CRMRealm");
        }
        return null;
    }
}
